﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
namespace WPFExcelReport
{
    public partial class ArticleTechnic : DocumentBase
    {
        #region-------------Properties-----------------------
        public OracleConnection OracleDB;
        public bool IsDirectlyCall = true;
        public OracleCommand orlReadCommand = new OracleCommand();
        FinishMasterData m_Data, m_DataX;
        private Dictionary<string, object> dicQueryParamater;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        GreigeMasterData m_GM;
        public DataSet SetUI;
        DataRow dwCurrentRecord;
        string UserID = "";
        string OracleDBConnString = "user id=intex;data source=intex3;password=intex";
        IntexReptServBLClient proxy;
        public TextBox TxtArticleNum
        {
            get
            {
                return ((TextBox)this.FindName("txtArticleNum"));
            }
        }
        public TextBox TxtArticleVar
        {
            get
            {
                return ((TextBox)this.FindName("txtArticleVar"));
            }
        }
        public TextBox TxtColor
        {
            get
            {
                return ((TextBox)this.FindName("txtColor"));
            }
        }
        public TextBox TxtFinish
        {
            get
            {
                return ((TextBox)this.FindName("txtFinish"));
            }
        }
        #endregion
        /// <summary>
        /// Constructor
        /// </summary>
        public ArticleTechnic()
        {
            InitializeComponent();
            this.Name = "工艺报表";
            SetUI = (DataSet)this.TryFindResource("setUI");
            if (SetUI == null)
            {
                SetUI = new DataSet();
            }

            if (OracleDB != null)
            {
                OracleDB.Close();
            }
            this.txtArticleNum.Text = "请选择品种";//"07"
        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            orlReadCommand = OracleDB.CreateCommand();
            orlReadCommand.Parameters.Add("OrdNum", OracleType.NVarChar).Value = "";
            m_Data = new FinishMasterData();
            m_Data.OracleDB = this.OracleDB;
            m_Data.proxy = this.proxy;
            txtUserID.Text = (string)dicParamater["User"];
            /*this.txtArticleVar.Text = "A1";//"000012";
            this.txtColor.Text = "RD01      ";
            this.txtFinish.Text = "F01";*/

        }
        private CollectionViewSource wAFARBENViewSource;


        #region ----------------------------Method------------------------
        private void ReloadColorway(string ArticleNum, string ArticleVar)
        {
            DataRow dwWAFARBEN = SetUI.Tables["WAFARBEN"].Clone().Rows.Add();
            dwWAFARBEN["WAFART"] = ArticleNum;
            dwWAFARBEN["WAFVAR"] = ArticleVar;
            DataTable dtColor = SetUI.Tables["ARTICLECOLOR"];
            dtColor.Clear();
            dtColor = m_GM.GetGreigeColorWay(dtColor, dwWAFARBEN);
            byte[] b;
            string value;
            foreach (DataRow dw in dtColor.Rows)
            {
                foreach (DataColumn dc in dtColor.Columns)
                {
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[dc.ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dw[dc.ColumnName] = value;
                }
            }
            SetUI.Tables["ARTICLECOLOR"].Clear();
            SetUI.AcceptChanges();
            SetUI.Merge(dtColor);
            this.listColor.DataContext = SetUI;
        }
        private void ReloadFinish(string ArticleNum, string ArticleVar)
        {
            DataRow dwWAFARBEN = SetUI.Tables["WAFARBEN"].Clone().Rows.Add();
            dwWAFARBEN["WAFART"] = ArticleNum;
            dwWAFARBEN["WAFVAR"] = ArticleVar;
            DataTable dtFinish = SetUI.Tables["ARTICLEFINISH"];
            dtFinish.Clear();
            dtFinish = m_GM.GetGreigeFinish(dtFinish, dwWAFARBEN);
            byte[] b;
            string value;
            foreach (DataRow dw in dtFinish.Rows)
            {
                foreach (DataColumn dc in dtFinish.Columns)
                {
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[dc.ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dw[dc.ColumnName] = value;
                }
            }
            SetUI.Merge(dtFinish);
            this.listFinish.DataContext = SetUI;
        }
        #endregion

        #region ----------------Events-----------------
        private void wAFARBENDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
                return;

            DataRowView drv = e.AddedItems[0] as DataRowView;
            if (drv == null)
                return;
            DataRow dwArticle = drv.Row;

            ReloadColorway(dwArticle["ArtNum"].ToString(), dwArticle["ArtVar"].ToString());
            ReloadFinish(dwArticle["ArtNum"].ToString(), dwArticle["ArtVar"].ToString());
            this.txtArticleNum.Text = dwArticle["ArtNum"].ToString();
            this.txtArticleVar.Text = dwArticle["ArtVar"].ToString();

        }

        private void btnQuery_Click(object sender, EventArgs e)
        {

            /*
            this.txtArticleNum.Text = "PV912102";//"07"
            this.txtArticleVar.Text = "A1";//"000012";
            this.cmbVar.Text = "A1";//"000012"; 
            this.cmbColor.Text = "黑色      ";
            this.cmbFinish.Text = "酶洗       ";
            
            _Control.dicReportParamater.Clear();
            _Control.dicReportParamater.Add("ArticleNum", this.txtArticleNum.Text);
            _Control.dicReportParamater.Add("ArticleVar", this.txtArticleVar.Text);
            _Control.dicReportParamater.Add("ArticleColor", this.txtColor.Text);
            _Control.dicReportParamater.Add("ArticleFin", this.txtFinish.Text);*/
            using (new LongOperation(this, "生成工艺表"))
            {
                this.GenerateReport();
            }

        }
       
        public void GenerateReport(string PrintType="DirectPrint")
        {
            try
            {
                DataSet dsParamaters = new DataSet();
                dsParamaters.Merge(SetUI);
                string ArticleNum = this.txtArticleNum.Text;
                string ArticleVar = this.txtArticleVar.Text;
                string ArticleColor = this.txtColor.Text;
                string ArticleFin = this.txtFinish.Text;
                if (IsDirectlyCall)
                {
                    ArticleColor = m_GM.Left(m_GM.ConvertGB2312To8859P1(ArticleColor) + "             ", 10);
                    ArticleFin = m_GM.Left(m_GM.ConvertGB2312To8859P1(ArticleFin) + "             ", 10);
                }
                dicParamater["ArticleNum"] = ArticleNum;
                dicParamater["ArticleVar"] = ArticleVar;
                dicParamater["ArticleColor"] = ArticleColor;
                dicParamater["ArticleFin"] = ArticleFin;
                string article = ArticleNum + ArticleVar + ArticleColor;
                #region GreigeMasterData


                dsParamaters = m_GM.LoadTableStructure(dsParamaters);

                DataRow dwWAFARBEN = dsParamaters.Tables["WAFARBEN"].Clone().Rows.Add();
                dwWAFARBEN["WAFART"] = ArticleNum;
                dwWAFARBEN["WAFVAR"] = ArticleVar;
                dwWAFARBEN["WAFZUSATZ"] = ArticleColor;
                dsParamaters = m_GM.BuildGreigeMasterData(dsParamaters, dwWAFARBEN);
                dsParamaters = m_GM.ImportDataTable(dsParamaters, dsParamaters.Tables["WAFARBEN"]);

                #endregion
                Tracer.Speak("已读取坯布信息");
                #region FinishMasterData
                FinishMasterData m_fm = new FinishMasterData();
                m_fm.OracleDB = this.OracleDB;
                m_fm.proxy = this.proxy;

                dwWAFARBEN = dsParamaters.Tables["WAFARBEN"].Clone().Rows.Add();
                dwWAFARBEN["WAFART"] = ArticleNum;
                dwWAFARBEN["WAFVAR"] = ArticleVar;
                dwWAFARBEN["WAFZUSATZ"] = ArticleFin;
                dsParamaters = m_fm.BuildFinishMasterData(dsParamaters, dwWAFARBEN);
                dsParamaters = m_fm.ImportDataTable(dsParamaters, dsParamaters.Tables["WAFINISH"]);

                #endregion
                Tracer.Speak("已读取成品信息");
                #region WarpMasterData
                WarpMasterData m_Wm = new WarpMasterData();
                m_Wm.OracleDB = this.OracleDB;
                m_Wm.proxy = this.proxy;
                dsParamaters = m_Wm.LoadTableStructure(dsParamaters);
                //BSFARB / BSFKART   /BSFKVAR     /BSFKFARBE  
                DataRow dwBSFARB = dsParamaters.Tables["BSFARB"].Clone().Rows.Add();
                foreach (DataRow dwWASTKE in dsParamaters.Tables["WASTKE"].Rows)
                {
                    //WAKKART              WAKKVAR WAKKFARBE
                    dwBSFARB["BSFKART"] = dwWASTKE["WAKKART"];
                    dwBSFARB["BSFKVAR"] = dwWASTKE["WAKKVAR"];
                    dwBSFARB["BSFKFARBE"] = m_Wm.GetGB2312Value(dwWASTKE, "WAKKFARBE");
                    dsParamaters = m_Wm.BuildWarpMasterData(dsParamaters, dwBSFARB);
                }

                foreach (DataRow dwBASTKE in dsParamaters.Tables["BASTKE"].Rows)
                {
                    //WAKKART              WAKKVAR WAKKFARBE
                    dwBSFARB["BSFKART"] = dwBASTKE["BAKKART"];
                    dwBSFARB["BSFKVAR"] = dwBASTKE["BAKKVAR"];
                    dwBSFARB["BSFKFARBE"] = m_Wm.GetGB2312Value(dwBASTKE, "BAKKFARBE");
                    dsParamaters = m_Wm.BuildWarpMasterData(dsParamaters, dwBSFARB);
                }

                #endregion
                Tracer.Speak("已读取轴信息");
                #region YarnMasterData
                YarnMasterData m_YM = new YarnMasterData();
                m_YM.OracleDB = this.OracleDB;
                m_YM.proxy = this.proxy;
                dsParamaters = m_YM.LoadTableStructure(dsParamaters);

                bool flag = true;
                string YarnArt;
                string YarnVar;
                string YarnColor;
                DataRow dwGSCOLOR;
                DataTable dtGSCOLOR;
                dtGSCOLOR = dsParamaters.Tables["GSCOLOR"].Clone();
                while (flag)
                {
                    #region WASTGA
                    foreach (DataRow dwWASTGA in dsParamaters.Tables["WASTGA"].Rows)
                    {
                        //WAGGART              WAGGVAR WAGGFARBE  
                        YarnArt = dwWASTGA["WAGGART"].ToString();
                        YarnVar = dwWASTGA["WAGGVAR"].ToString();
                        YarnColor = m_YM.GetGB2312Value(dwWASTGA, "WAGGFARBE");
                        if (!m_YM.YarnExist(dsParamaters.Tables["GSDAT"], YarnArt, YarnVar))
                        {
                            if (!m_YM.YarnExist(dtGSCOLOR, YarnArt, YarnVar))
                            {
                                dwGSCOLOR = dtGSCOLOR.Rows.Add();
                                dwGSCOLOR["GSCART"] = YarnArt;
                                dwGSCOLOR["GSCVAR"] = YarnVar;
                                dwGSCOLOR["GSCFARBE"] = YarnColor;
                            }
                        }
                    }
                    #endregion

                    #region BASTGA
                    foreach (DataRow dwBASTGA in dsParamaters.Tables["BASTGA"].Rows)
                    {

                        //GSCOLOR/  GSCART               GSCVAR GSCFARBE  
                        YarnArt = dwBASTGA["BAGGART"].ToString();
                        YarnVar = dwBASTGA["BAGGVAR"].ToString();
                        YarnColor = m_YM.GetGB2312Value(dwBASTGA, "BAGGFARBE");
                        if (!m_YM.YarnExist(dsParamaters.Tables["GSDAT"], YarnArt, YarnVar))
                        {
                            if (!m_YM.YarnExist(dtGSCOLOR, YarnArt, YarnVar))
                            {
                                dwGSCOLOR = dtGSCOLOR.Rows.Add();
                                dwGSCOLOR["GSCART"] = YarnArt;
                                dwGSCOLOR["GSCVAR"] = YarnVar;
                                dwGSCOLOR["GSCFARBE"] = YarnColor;
                            }
                        }
                    }
                    #endregion

                    #region GASTGA
                    foreach (DataRow dwGASTGA in dsParamaters.Tables["GASTGA"].Rows)
                    {

                        YarnArt = dwGASTGA["GAGGART"].ToString();
                        YarnVar = dwGASTGA["GAGGVAR"].ToString();
                        YarnColor = dwGASTGA["GAGGFARBE"].ToString();
                        if (!m_YM.YarnExist(dsParamaters.Tables["GSDAT"], YarnArt, YarnVar))
                        {
                            if (!m_YM.YarnExist(dtGSCOLOR, YarnArt, YarnVar))
                            {
                                dwGSCOLOR = dtGSCOLOR.Rows.Add();
                                dwGSCOLOR["GSCART"] = YarnArt;
                                dwGSCOLOR["GSCVAR"] = YarnVar;
                                dwGSCOLOR["GSCFARBE"] = YarnColor;
                            }
                        }
                    }
                    #endregion
                    flag = false;
                    foreach (DataRow dwYan in dtGSCOLOR.Rows)
                    {
                        flag = true;
                        dsParamaters = m_YM.BuildYarnMasterData(dsParamaters, dwYan);
                    }
                    dtGSCOLOR.Clear();

                }
                #endregion
                Tracer.Speak("已读取纱线信息");
                #region PatternMasterData
                PatternMasterData m_PatternMasterData = new PatternMasterData();
                m_PatternMasterData.OracleDB = this.OracleDB;
                m_PatternMasterData.proxy = this.proxy;
                dsParamaters = m_PatternMasterData.LoadTableStructure(dsParamaters);
                DataTable dtPattern;
                if (!dsParamaters.Tables.Contains("Pattern"))
                {
                    dtPattern = new DataTable("Pattern");
                    dtPattern.Columns.Add("PatternTable", typeof(String));
                    dtPattern.Columns.Add("PatternType", typeof(String));
                    dtPattern.Columns.Add("PatternKeyName", typeof(String));
                    dtPattern.Columns.Add("PatternKey", typeof(String));
                    dsParamaters.Tables.Add(dtPattern);
                }
                else
                {
                    dtPattern = dsParamaters.Tables["Pattern"];
                    dtPattern.Clear();
                    dtPattern.AcceptChanges();
                }
                DataRow dwPattern;

                #region WarpPattern
                foreach (DataRow dwTmp in dsParamaters.Tables["BSSATZ"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTSAER";
                    dwPattern["PatternType"] = "WarpPattern";
                    dwPattern["PatternKeyName"] = "WTBSRFNR";
                    dwPattern["PatternKey"] = dwTmp["BSSRFNR"].ToString().Trim();

                }
                #endregion
                this.textBox1.Text = "已读经纱排花信息";
                #region SelvagePattern
                foreach (DataRow dwTmp in dsParamaters.Tables["WASTKE"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTLEIST";
                    dwPattern["PatternType"] = "SelvageLeftPattern";
                    dwPattern["PatternKeyName"] = "WTLLEIST";
                    dwPattern["PatternKey"] = dwTmp["WAKLLEIST"].ToString().Trim();
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTLEIST";
                    dwPattern["PatternType"] = "SelvageRightPattern";
                    dwPattern["PatternKeyName"] = "WTLLEIST";
                    dwPattern["PatternKey"] = dwTmp["WAKRLEIST"].ToString().Trim();
                }
                #endregion
                this.textBox1.Text = "已布边轴信息";
                #region WeaveRepeat /Denting
                foreach (DataRow dwTmp in dsParamaters.Tables["WASTAMM"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "SDDAT";
                    dwPattern["PatternType"] = "WeaveRepeat";
                    dwPattern["PatternKeyName"] = "SDKEY";
                    //select * from sddat where SDSA='0109' AND SDKEY Like '%4226%V'
                    dwPattern["PatternKey"] = dwTmp["WABIND"].ToString().Trim();

                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTEINZ";
                    dwPattern["PatternType"] = "Denting";
                    dwPattern["PatternKeyName"] = "WTEEINZNR";
                    dwPattern["PatternKey"] = dwTmp["WAEINZNR"].ToString().Trim();

                }
                #endregion
                this.textBox1.Text = "已读取穿综插筘信息";
                #region WeftPattern
                foreach (DataRow dwTmp in dsParamaters.Tables["WTGEW"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTSCHUSS";
                    dwPattern["PatternType"] = "WeftPattern";
                    dwPattern["PatternKeyName"] = "WTSSFLGNR";
                    dwPattern["PatternKey"] = dwTmp["WTGSFLG"].ToString().Trim();

                }
                #endregion
                this.textBox1.Text = "已读取纬向排花信息";
                #region DraftingNumber

                foreach (DataRow dwTmp in dsParamaters.Tables["WASTPASS"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTPASS";
                    dwPattern["PatternType"] = "DraftingNumber";
                    dwPattern["PatternKeyName"] = "WTPPASSNR";
                    dwPattern["PatternKey"] = dwTmp["WSPPASS"].ToString().Trim();

                }
                #endregion
                this.textBox1.Text = "已读穿综信息";
                foreach (DataRow dwPatterns in dtPattern.Rows)
                {
                    dsParamaters = m_PatternMasterData.BuildPatternMasterData(dsParamaters, dwPatterns);
                    this.textBox1.Text = "已读花型信息：" + dwPatterns["PatternType"].ToString();
                }
                #endregion

                Tracer.Speak("开始生成报表");
                m_DataX = new FinishMasterData(dicParamater);
                m_DataX.proxy = this.proxy;
                m_DataX.OracleDB = this.OracleDB;
                GreigeMasterReport m_rpt = new GreigeMasterReport(dicParamater);
                m_rpt.dsSource = dsParamaters;
                m_rpt.exAgent = m_DataX.exAgent;
                m_rpt.WriteExcelReport(PrintType);

                Tracer.Speak("报表生成完毕");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void listColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
                return;
            DataRowView drv = e.AddedItems[0] as DataRowView;
            DataRow dwArticle = drv.Row;
            this.txtColor.Text = dwArticle["ArtColor"].ToString();
        }

        private void listFinish_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
                return;
            DataRowView drv = e.AddedItems[0] as DataRowView;
            DataRow dwArticle = drv.Row;
            this.txtFinish.Text = dwArticle["ArtFin"].ToString();
        }
        #endregion

        #region ---------------INTERNAL------------------

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //dsParamaters = ((IntexReportClient.DataSetIntex)(this.FindResource("dataSetIntex")));
                InitDataBinding();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;

        }
        public void InitDataBinding()
        {
            m_GM = new GreigeMasterData(OracleDB,proxy); 
            if (!this.SetUI.Tables.Contains("ARTICLEVAR"))
            {
                this.SetUI.Tables.Add("ARTICLEVAR");
            }
            if (!this.SetUI.Tables.Contains("ARTICLE"))
            {
                this.SetUI.Tables.Add("ARTICLE");
            }
            if (!this.SetUI.Tables.Contains("ARTICLEFINISH"))
            {
                this.SetUI.Tables.Add("ARTICLEFINISH");
            }
            if (!this.SetUI.Tables.Contains("ARTICLECOLOR"))
            {
                this.SetUI.Tables.Add("ARTICLECOLOR");
            }
            orlReadCommand = OracleDB.CreateCommand();

            #region "ARTICLE"
            orlReadCommand.CommandText = "SELECT WAART AS ArtNum, WAVAR as ArtVar,WABEZ as ArtDes"
            + " FROM INTEX.WASTAMM WHERE RowNum<1";

            dsResult = m_GM.Connect2Proxy(orlReadCommand);

            if (dsResult.Tables.Count > 0)
            {
                dsResult.Tables[0].TableName = "ARTICLE";

                foreach (DataTable dtTemp in dsResult.Tables)
                {
                    SetUI = m_GM.ImportDataTable(SetUI, dtTemp);
                }
            }
            #endregion

            #region "ARTICLECOLOR"
            orlReadCommand.CommandText = "SELECT WAFART as ArtNum,	WAFVAR as ArtVar,	 WAFZUSATZ as ArtColor,WAFBEZ as ColorDes"
                + " FROM INTEX.WAFARBEN WHERE RowNum<1";

            dsResult = m_GM.Connect2Proxy(orlReadCommand);

            if (dsResult.Tables.Count > 0)
            {
                dsResult.Tables[0].TableName = "ARTICLECOLOR";
                SetUI.Merge(dsResult);
            }
            #endregion

            #region "ARTICLEFINISH"

            orlReadCommand.CommandText = "SELECT WAFART as ArtNum,	WAFVAR as ArtVar,	 WAFZUSATZ as ArtFin,WAFBEZ as FinishDes"
          + " FROM INTEX.WAFARBEN WHERE RowNum<1";

            dsResult = m_GM.Connect2Proxy(orlReadCommand);

            if (dsResult.Tables.Count > 0)
            {
                dsResult.Tables[0].TableName = "ARTICLEFINISH";

                SetUI.Merge(dsResult);
            }
            #endregion

            #region "WAFARBEN"
            orlReadCommand.CommandText = "SELECT * "
    + " FROM INTEX.WAFARBEN WHERE RowNum<1";

            dsResult = m_GM.Connect2Proxy(orlReadCommand);

            if (dsResult.Tables.Count > 0)
            {
                dsResult.Tables[0].TableName = "WAFARBEN";
                SetUI.Merge(dsResult);
            }
            #endregion

            #region "Combo"
            SetUI.AcceptChanges();
            this.wAFARBENDataGrid.DataContext = SetUI;
            #endregion
        }
        #endregion

        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            string userID = m_Data.Left(txtUserID.Text.ToUpper() + "        ", 8);
            DataSet SetUI = new DataSet();
            userID = "FPDE    ";
            m_Data.UserID = userID;
            UserID = userID;
            SetUI.Merge(m_Data.LoadWAASTAMM(UserID));
            SetUI.AcceptChanges();
            this.wAFARBENDataGrid.DataContext = SetUI;
            return;

            string Mandant = txtMANDANT.Text.ToUpper();

            System.Security.SecureString SPassword = txtPassword.SecurePassword;
            DataSet setResult = m_Data.LogIn(Mandant, userID, SPassword);
            foreach (DataRow dwTemp in setResult.Tables["HRSTAMM"].Rows)
            {

                //DataRow dwUser = setResult.Tables[0].Rows[0];
                txtSPRACHKZ.Text = dwTemp["HRSPRKZ"].ToString();
                btnQuery.IsEnabled = true;
                UserID = userID;
                m_Data.UserID = userID;
                m_Data.MANDANT = Mandant;
                m_Data.SPRACHKZ = txtSPRACHKZ.Text.Trim();
                SetUI.Merge(m_Data.LoadWAASTAMM(UserID));
                SetUI.AcceptChanges();
                this.wAFARBENDataGrid.DataContext = SetUI;
            }
        }
    }
}
